
/**
 * 创建entity model
 */

import Entity from '../Entity'

const DEFAULT_STYLE = {
  scale : 1.0,
  shadows : Cesium.ShadowMode.DISABLED,
}

export default class Model extends Entity{
  /**
  * 创建一个model实体对象
  * @param {Cartesian3} positions
  * @param {String} modelUrl 
  */
  constructor(positions , modelUrl , options = {}) {
    super()
    this.delegate = new Cesium.Entity({ model : {} })

    this._modelUrl = modelUrl
    this._positions = positions
    this._style = {
      ...DEFAULT_STYLE,
      ...options
    }
    this._type = 'model'
    this.mounted()
  }
  
  /**
  * 初始化对象属性
  */
  
  mounted(){
    this.style = this._style
    this.positions = this._positions
    this.modelUrl = this._modelUrl
  }

  /** 
  * @param {*} style 设置模型参数
  * @returns 
  */

  setStyle(style){
    if(!style) return
    delete style['position']
    Object.assign(this._style , {...style})
    Object.assign(this.delegate.model, {...this._style})
  }

  get style(){
    return this._style
  }

  set style(val){
    Object.assign(this._style , {...val})
    Object.assign(this.delegate.model , {...this._style})
  }

  /**
  * 获取位置信息
  */

  get positions(){
    return this._positions
  }
  /**
  * 设置位置信息
  */
  set positions(positions){
    this._positions = positions
    this.delegate.position = this._positions
  }

  get modelUrl(){
    return this._modelUrl
  }

  set modelUrl(val){
    this._modelUrl = val
    this.delegate.model.uri = this._modelUrl
  }
}
